#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int a[N];
ll sum[N << 2], mx[N << 2];

void pushup(int p) {
  sum[p] = sum[p << 1] + sum[p << 1 | 1];
  mx[p] = max(mx[p << 1], mx[p << 1 | 1]);
}
void build(int p, int l, int r) {
  if (l == r) {
    sum[p] = mx[p] = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  pushup(p);
}
void update(int x, int v, int p, int l, int r) {
  if (l == r) {
    sum[p] = mx[p] = v;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(x, v, p << 1, l, mid);
  else
    update(x, v, p << 1 | 1, mid + 1, r);
  pushup(p);
}
void update(int L, int R, int x, int p, int l, int r) {
  if (mx[p] < x) return;
  if (l == r) {
    sum[p] = mx[p] = sum[p] % x;
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) update(L, R, x, p << 1, l, mid);
  if (R > mid) update(L, R, x, p << 1 | 1, mid + 1, r);
  pushup(p);
}
ll query(int L, int R, int p, int l, int r) {
  if (L <= l && R >= r) return sum[p];
  int mid = (l + r) >> 1;
  ll res = 0;
  if (L <= mid) res += query(L, R, p << 1, l, mid);
  if (R > mid) res += query(L, R, p << 1 | 1, mid + 1, r);
  return res;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  build(1, 1, n);
  while (m--) {
    int op, l, r, k, x;
    cin >> op;
    if (op == 1) {
      cin >> l >> r;
      cout << query(l, r, 1, 1, n) << endl;
    }
    if (op == 2) {
      cin >> l >> r >> x;
      update(l, r, x, 1, 1, n);
    }
    if (op == 3) {
      cin >> k >> x;
      update(k, x, 1, 1, n);
    }
  }
  return 0;
}